package com.example.dingdong.daomain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * @ClassName: RouterEntity
 * @Description: 路由实体
 * @Author chengwenxing
 * @DateTime 2021-03-31 
 */
@Entity
@Table(name ="router_entity")
public class RouterEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;

	/**
	 * 父组织（多对一）
	 */
	@JSONField(serialize = false)
	@JoinColumn(name = "parent_id")
	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private RouterEntity parent;

	/**
	 * 子组织（一对多）
	 */
	@JSONField(serialize = false)
	@JoinColumn(name = "parent_id")
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private List<RouterEntity> children = new ArrayList<>();

	/**
	 * 路由-角色（多对多）
	 */
	@JSONField(serialize = false)
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "router_relate_role", joinColumns = @JoinColumn(name = "router_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
	private List<RoleEntity> joinRoleList = new ArrayList<>();

	/**
	 * 路由路径
	 */
	private String path;

	/**
	 * 路由排序
	 */
	private int sort;

	/**
	 * 组件路径
	 */
	private String component;

	/**
	 * 路由名称
	 */
	private String name;

	/**
	 * 侧边栏图标
	 */
	private String icon;

	/**
	 * 是否严格匹配'/'这个符号
	 */
	private boolean strict;

	/**
	 * 是否进行路由匹配
	 */
	private boolean exact;

	/**
	 * 重定向
	 */
	private String redirect;

	/**
	 * 删除标识
	 */
	private boolean delFlag = true;

	/**
	 * 构造器
	 */
	public RouterEntity(String path, int sort, String component, String name, String icon, boolean strict,
			boolean exact, String redirect) {
		this.path = path;
		this.sort = sort;
		this.component = component;
		this.name = name;
		this.icon = icon;
		this.strict = strict;
		this.exact = exact;
		this.redirect = redirect;
	}

	/**
	 * 构造器
	 */
	public RouterEntity() {
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public RouterEntity getParent() {
		return parent;
	}

	public void setParent(RouterEntity parent) {
		this.parent = parent;
	}

	public List<RouterEntity> getChildren() {
		return children;
	}

	public void setChildren(List<RouterEntity> children) {
		this.children = children;
	}

	public List<RoleEntity> getJoinRoleList() {
		return joinRoleList;
	}

	public void setJoinRoleList(List<RoleEntity> joinRoleList) {
		this.joinRoleList = joinRoleList;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

	public String getComponent() {
		return component;
	}

	public void setComponent(String component) {
		this.component = component;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public boolean isStrict() {
		return strict;
	}

	public void setStrict(boolean strict) {
		this.strict = strict;
	}

	public boolean isExact() {
		return exact;
	}

	public void setExact(boolean exact) {
		this.exact = exact;
	}

	public String getRedirect() {
		return redirect;
	}

	public void setRedirect(String redirect) {
		this.redirect = redirect;
	}

	public boolean isDelFlag() {
		return delFlag;
	}

	public void setDelFlag(boolean delFlag) {
		this.delFlag = delFlag;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((children == null) ? 0 : children.hashCode());
		result = prime * result + ((component == null) ? 0 : component.hashCode());
		result = prime * result + (delFlag ? 1231 : 1237);
		result = prime * result + (exact ? 1231 : 1237);
		result = prime * result + ((icon == null) ? 0 : icon.hashCode());
		result = prime * result + id;
		result = prime * result + ((joinRoleList == null) ? 0 : joinRoleList.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((parent == null) ? 0 : parent.hashCode());
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		result = prime * result + ((redirect == null) ? 0 : redirect.hashCode());
		result = prime * result + sort;
		result = prime * result + (strict ? 1231 : 1237);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RouterEntity other = (RouterEntity) obj;
		if (children == null) {
			if (other.children != null)
				return false;
		} else if (!children.equals(other.children))
			return false;
		if (component == null) {
			if (other.component != null)
				return false;
		} else if (!component.equals(other.component))
			return false;
		if (delFlag != other.delFlag)
			return false;
		if (exact != other.exact)
			return false;
		if (icon == null) {
			if (other.icon != null)
				return false;
		} else if (!icon.equals(other.icon))
			return false;
		if (id != other.id)
			return false;
		if (joinRoleList == null) {
			if (other.joinRoleList != null)
				return false;
		} else if (!joinRoleList.equals(other.joinRoleList))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (parent == null) {
			if (other.parent != null)
				return false;
		} else if (!parent.equals(other.parent))
			return false;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		if (redirect == null) {
			if (other.redirect != null)
				return false;
		} else if (!redirect.equals(other.redirect))
			return false;
		if (sort != other.sort)
			return false;
		if (strict != other.strict)
			return false;
		return true;
	}
}